<template>
  <div>
    <button @click="isShow = !isShow">显示/隐藏</button>
    <!-- 动画效果封装 -->
    <!-- appear属性为真，则页面刷新后即执行 move-enter-active-->
    <transition name="moveAnimation" :appear="true">
      <h2 class="ani" v-show="isShow">{{msg}}</h2>
    </transition>

    <transition-group name="moveTransition" :appear="true">
      <h2 class="tran" v-show="!isShow" key="1">{{msg}}</h2>
      <h2 class="tran" v-show="isShow" key="2">{{msg}}</h2>
    </transition-group>
  </div>
</template>

<script>
export default {
  name: 'Test',
  data() {
    return {
      msg: '哈哈哈哈哈',
      isShow: true
    }
  }
}
</script>

<style>
h2 {
  background-color: pink;
}

/* 动画效果 */
.moveAnimation-enter-active {
  animation: move 1s linear;
}
.moveAnimation-leave-active {
  animation: move 1s linear reverse;
}
@keyframes move {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

/* 过渡效果 */

/* 进入的起点，离开的终点 */
.moveTransition-enter,
.moveTransition-leave-to {
  transform: translateX(-100%);
}
/* 离开的起点，进入的终点 */
.moveTransition-enter-to,
.moveTransition-leave {
  transform: translateX(0);
}
/* 添加过渡 */
.moveTransition-enter-active,
.moveTransition-leave-active {
  transition: 1s linear;
}
</style>